package com.example.controller;

import com.example.pojo.SpecGroup;
import com.example.pojo.SpecParam;
import com.example.service.SpecificationService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/spec")
public class SpecificationController {

	@Autowired
	private SpecificationService specService;

	// 根据分类id查询规格组
	@GetMapping("groups/{cid}")
	public ResponseEntity<List<SpecGroup>> queryGroupByCid(@PathVariable("cid") Long cid) {
		return ResponseEntity.ok(specService.queryGroupByCid(cid));
	}

	// 根据组id查询参数
	@GetMapping("/params")
	public ResponseEntity<List<SpecParam>> queryParamByGid(
			@RequestParam(value = "gid", required = false) Long gid,
			@RequestParam(value = "cid", required = false) Long cid,
			@RequestParam(value = "searching", required = false) Boolean searching
	                                                      ) {
		return ResponseEntity.ok(specService.queryParamByGid(gid, cid, searching));
	}

	@GetMapping("/name")
	public ResponseEntity<List<SpecGroup>> queryNameGid(@RequestParam(value = "name") String name) {

		return ResponseEntity.ok(specService.queryNameGid(name));
	}
}
